//
//  KQMessageCustomTipsContent.swift
//  KangYunYouJia
//
//  Created by zhouxiang on 2020/12/17.
//  Copyright © 2020 zhoux@zzkqdc.com. All rights reserved.
//

import UIKit

class KQMessageCustomTipsContent: NSObject, KQMessageContentType {
    
    public weak var delegate: KQMessageDelegate?
    
    open var layoutMargins: UIEdgeInsets = .zero
    
    open class var viewType: KQMessageContentViewType.Type {
        return KQMessageCustomTipsContentView.self
    }
    
    public init(title: String, repairId: String) {
        self.title = title
        self.repairId = repairId
        super.init()
    }
    
    open var title: String?
    open var repairId: String?
    
    open func sizeThatFits(_ size: CGSize) -> CGSize {
        
        let attr = NSMutableAttributedString(string: "\(self.title ?? "")，点击此处查看>>")
        attr.addAttributes([NSAttributedString.Key.font: UIFont(name: KQCHAT_FONT_NAME, size: 12)!,
                            NSAttributedString.Key.foregroundColor: KQCHAT_COLOR(153, 153, 153)], range: NSMakeRange(0, attr.length - 8))
        attr.addAttributes([NSAttributedString.Key.font: UIFont(name: KQCHAT_FONT_NAME, size: 12)!,
                            NSAttributedString.Key.foregroundColor: KQCHAT_COLOR(2, 146, 186)], range: NSMakeRange(attr.length - 8, 8))
                                    
        let mattrSize = attr.boundingRect(with: CGSize(width: 250.0, height: CGFloat.greatestFiniteMagnitude), options: [.usesLineFragmentOrigin,.usesFontLeading], context: nil)
        let size = CGSize(width: mattrSize.size.width + 10, height: mattrSize.size.height)
        return size
    }

}


